import logging
from redis import StrictRedis


class Config(object):
    # 项目的配置
    DEBUG = True


    SECRET_KEY = "Yl9JM/phRcQ2NMYYcwflIfG7MEz13e7dBqBpKrh5lZguZ2aA4dHJJ24M0EeSdmu1"

    # 为数据库添加配置
    SQLALCHEMY_DATABASE_URI = "mysql://root:mysql@127.0.0.1:3306/information27"
    SQLALCHEMY_TRACK_MODIFICATIONS = False
    # 设置为自动调用db.session.commit() 意思是自动提交!!!!
    # 也可手动提交不冲突
    SQLALCHEMY_COMMIT_ON_TEARDOWN = True
    # redis的配置
    REDIS_HOST = "127.0.0.1"
    REDIS_PORT = 6379
    # Session保存配置
    SESSION_TYPE = "redis"
    # 指定 session 保存到 redis 中
    SESSION_USE_SIGNER = True  # 让 cookie 中的 session_id 被加密签名处理
    SESSION_REDIS = StrictRedis(host=REDIS_HOST, port=REDIS_PORT)
    SESSION_PERMANENT = False
    # 使用 redis 的实例
    PERMANENT_SESSION_LIFETIME = 86400 * 2 # session 的有效期，单位是秒
#     设置日志等级
    LOG_LEVEL = logging.DEBUG

class DevelopmentConfig(Config):
    # 开发环境下的配置

    DEBUG = True

class ProductionConfig(Config):
    # 生产环境下的配置
    DEBUG = False
    # SQLALCHEMY_DATABASE_URI = "mysql://root:mysql@127.0.0.1:3306/information27"
    LOG_LEVEL = logging.WARNING


class TestingConfig(Config):
    # 单元测试环境下的配置
    DEBUG = True
    TESTING = True


config = {
    "development":DevelopmentConfig,
    "production":ProductionConfig,
    "testing":TestingConfig
}